package com.xjgc;


//import com.xjgc.msi.SapToMsiReal;
//import com.xjgc.msi.SapToMsiRealImplService;

import com.xjgc.msi.exo.wsclient.sap.zjk_back02.ZxjZjkBack02Port;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.jeecg.common.util.DateUtils;

import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;

/**
 * @author: 小逗号
 * @date: 2023-12-20
 * @description:
 * @since:
 */
public class Test {
    static String addressWsdl = "http://localhost:8080/MsiWebServer/ws/SapToMsiReal?wsdl";
    static String address = "http://localhost:8080/MsiWebServer/ws/SapToMsiReal";
    static HTTPClientPolicy httpClient = new HTTPClientPolicy();

    static {
        httpClient.setConnectionTimeout(1000);
        httpClient.setReceiveTimeout(120000);
    }

    public static void main(String[] args) {
        String serialNo = DateUtils.getDataString(DateUtils.datetimeFormat.get());


        try {
            Test.test2(serialNo);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }


    }

    public static void test3() {
        ClientFactoryBean clientFactoryBean = new ClientFactoryBean();

        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(clientFactoryBean);
        jaxWsProxyFactoryBean.setServiceClass(ZxjZjkBack02Port.class);
        System.out.println(jaxWsProxyFactoryBean.getAddress());
        jaxWsProxyFactoryBean.setAddress("address");
        System.out.println(jaxWsProxyFactoryBean.getAddress());
        jaxWsProxyFactoryBean.setWsdlURL("wsdl");
        jaxWsProxyFactoryBean.setUsername("username");
        jaxWsProxyFactoryBean.setPassword("password");
        //Object o = jaxWsProxyFactoryBean.create();
    }

    public static void test2(String serialNo) throws MalformedURLException {
        URL url = new URL(address);
//        SapToMsiReal sapToMsiReal = new SapToMsiRealImplService(url).getSapToMsiRealPort();
//        Client client = JaxWsClientProxy.getClient(sapToMsiReal);
        //Client client = ClientProxy.getClient(sapToMsiReal);

//        Conduit conduit = client.getConduit();
//        HTTPConduit httpConduit = (HTTPConduit) conduit;
//        System.out.println(httpConduit.getAddress());
//        httpConduit.setClient(httpClient);
//        System.out.println("---------------------------");
//        System.out.println(httpConduit.getAddress());

        ClientFactoryBean clientFactoryBean = new ClientFactoryBean();

        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(clientFactoryBean);
        jaxWsProxyFactoryBean.setServiceClass(ZxjZjkBack02Port.class);
        System.out.println(jaxWsProxyFactoryBean.getAddress());
        jaxWsProxyFactoryBean.setAddress("address");
        jaxWsProxyFactoryBean.setWsdlURL("wsdl");
        jaxWsProxyFactoryBean.setUsername("username");
        jaxWsProxyFactoryBean.setPassword("password");

        try {
            System.out.println("=====================");
            System.out.println(DateUtils.getDataString(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS")));
//            String s = sapToMsiReal.realReceive(wsTask, serialNo, xml, sys);
//            System.out.println(s);
//            System.out.println("=====================");
//            System.out.println(DateUtils.getDataString(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS")));

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("=====================");
            System.out.println(DateUtils.getDataString(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS")));

        }

    }


    public static void test(String serialNo) {

//        JaxWsClientProxy.getClient()
        JaxWsDynamicClientFactory jaxWsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance();
        try {
            Client client = jaxWsDynamicClientFactory.createClient("http://10.10.6.27:8080/MsiWebServer/ws/SapToMsiReal?wsdl");
            HTTPConduit conduit = (HTTPConduit) client.getConduit();
            HTTPConduit httpConduit = (HTTPConduit) conduit;
            conduit.setClient(httpClient);
            Object[] results = client.invoke(wsMethod, wsTask, serialNo, xml, sys);
            Object result = results[0];
            System.out.println(result.toString());
            client.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }

    static String wsMethod = "realReceive";
    static String wsTask = "ZXJ_MES_EBELN";
    static String sys = "test";
    static String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<REQUEST_DATA>\n" +
            "\t<ITEM>\n" +
            "\t  <EBELN>4570105017</EBELN>\n" +
            "\t  <EBELP>00010</EBELP>\n" +
            "\t  <BSART>ZM59</BSART>\n" +
            "\t  <LIFNR>1169000021</LIFNR>\n" +
            "\t  <GYSMC>许继电气股份有限公司制造中心</GYSMC>\n" +
            "\t  <BUKRS>9250</BUKRS>\n" +
            "\t  <EKGRP>8W2</EKGRP>\n" +
            "\t  <BEDAT>20221115</BEDAT>\n" +
            "\t  <ERNAM>XJ-YUANLH</ERNAM>\n" +
            "\t  <WERKS>5036</WERKS>\n" +
            "\t  <ZGCMC>许继电气保护自动化系统工厂</ZGCMC>\n" +
            "\t  <KNTTP>E</KNTTP>\n" +
            "\t  <VBELN>4000689947</VBELN>\n" +
            "\t  <VBELP>001000</VBELP>\n" +
            "\t  <MATNR>000000000704236743</MATNR>\n" +
            "\t  <TXZ01>户内柜;JPN1Z-24C2-G1/2260×800×600;钢板;喷涂;IP3</TXZ01>\n" +
            "\t  <MENGE>1.000</MENGE>\n" +
            "\t  <MEINS>Z25</MEINS>\n" +
            "\t  <LMEIN>Z25</LMEIN>\n" +
            "\t  <BRTWR>2691.00</BRTWR>\n" +
            "\t  <ZNETPR>2691.00</ZNETPR>\n" +
            "\t  <BPRME>Z25</BPRME>\n" +
            "\t  <EINDT>20221130</EINDT>\n" +
            "\t  <MWSKZ>J0</MWSKZ>\n" +
            "\t  <WEMNG>1.000</WEMNG>\n" +
            "\t  <ZMENG>1.000</ZMENG>\n" +
            "\t  <ZWRBTR>2691.00</ZWRBTR>\n" +
            "\t  <BUDAT>20221128</BUDAT>\n" +
            "\t  <FRGKE>X</FRGKE>\n" +
            "\t  <LOEKZ></LOEKZ>\n" +
            "\t  <ZDDDW>台</ZDDDW>\n" +
            "\t  <ZJGDW>Z25</ZJGDW>\n" +
            "\t  <PEINH>1</PEINH>\n" +
            "\t  <HXMWB></HXMWB>\n" +
            "\t  <BATXT>许继集团内部采购订单</BATXT>\n" +
            "\t  <LGORT>3631</LGORT>\n" +
            "\t  <LGOBE>原材料-生产装置库</LGOBE>\n" +
            "\t  <TEXT1>0% 进项税，中国</TEXT1>\n" +
            "\t  <DATUM>20221221</DATUM>\n" +
            "\t  <UZEIT>001418</UZEIT>\n" +
            "\t  <STATUS>1</STATUS>\n" +
            "\t  <UID>bzgs</UID>\n" +
            "\t  <BUDAT_MKPF>20221128</BUDAT_MKPF>\n" +
            "\t  <NETPR>2691.00</NETPR>\n" +
            "\t  <SUM_NETPR>2691.00</SUM_NETPR>\n" +
            "\t  <ZTERM>G001N</ZTERM>\n" +
            "\t  <NAME_LAST>袁林虎</NAME_LAST>\n" +
            "\t  <BANFN>0143168567</BANFN>\n" +
            "\t  <BNFPO>10</BNFPO>\n" +
            "\t  <IDNLF></IDNLF>\n" +
            "\t  <POSID></POSID>\n" +
            "\t  <create_time>2022-11-15 00:00:00.000000</create_time>\n" +
            "\t  <BADAT></BADAT>\n" +
            "\t  <URZZT></URZZT>\n" +
            "\t</ITEM>\n" +
            "</REQUEST_DATA>";
}
